Proper connect_port
[juce-lv2.git] / juce / source / extras / the jucer / src / model / paintelements / jucer_PaintElementUndoableAction.h
blob4a7e7bc321f6607aee9f0c37ba9e8443619127ad
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__
27 #define __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__
29 #include "../../ui/jucer_JucerDocumentHolder.h"
30 #include "jucer_PaintElementGroup.h"
33 //==============================================================================
34 /**
36 template <class ElementType>
37 class PaintElementUndoableAction : public UndoableAction
39 public:
40 PaintElementUndoableAction (ElementType* const element)
41 : routine (*element->getOwner()),
42 elementIndex (element->getOwner()->indexOfElement (element))
44 jassert (element != 0);
46 if (elementIndex < 0)
47 findGroupIndices (element->getOwner(), element);
49 jassert (elementIndex >= 0);
52 ~PaintElementUndoableAction()
56 ElementType* getElement() const
58 if (containerGroups.size() > 0)
60 PaintElementGroup* group = 0;
61 group = dynamic_cast <PaintElementGroup*> (routine.getElement (containerGroups.getFirst()));
63 if (group == 0)
64 return 0;
66 for (int i = 1; i < containerGroups.size(); ++i)
68 group = dynamic_cast <PaintElementGroup*> (group->getElement (containerGroups.getUnchecked(i)));
70 if (group == 0)
71 return 0;
74 ElementType* const e = dynamic_cast <ElementType*> (group->getElement (elementIndex));
75 jassert (e != 0);
76 return e;
78 else
80 ElementType* const e = dynamic_cast <ElementType*> (routine.getElement (elementIndex));
81 jassert (e != 0);
82 return e;
86 int getSizeInUnits() { return 2; }
88 protected:
89 PaintRoutine& routine;
90 int elementIndex;
91 Array <int> containerGroups;
93 void changed() const
95 jassert (routine.getDocument() != 0);
96 routine.getDocument()->changed();
99 void showCorrectTab() const
101 JucerDocumentHolder* const docHolder = JucerDocumentHolder::getActiveDocumentHolder();
103 if (docHolder != 0)
104 docHolder->showGraphics (&routine);
106 if (routine.getSelectedElements().getNumSelected() == 0)
108 ElementType* const e = dynamic_cast <ElementType*> (routine.getElement (elementIndex));
110 if (e != 0)
111 routine.getSelectedElements().selectOnly (e);
115 private:
116 void findGroupIndices (PaintRoutine* const routine, PaintElement* const element)
118 for (int i = routine->getNumElements(); --i >= 0;)
120 PaintElementGroup* const pg = dynamic_cast <PaintElementGroup*> (routine->getElement (i));
122 if (pg != 0 && pg->containsElement (element))
124 containerGroups.add (i);
125 findGroupIndices (pg, element);
130 void findGroupIndices (PaintElementGroup* const group, PaintElement* const element)
132 elementIndex = group->indexOfElement (element);
133 if (elementIndex < 0)
135 for (int i = group->getNumElements(); --i >= 0;)
137 PaintElementGroup* pg = dynamic_cast <PaintElementGroup*> (group->getElement (i));
139 if (pg != 0 && pg->containsElement (element))
141 containerGroups.add (i);
142 findGroupIndices (pg, element);
148 PaintElementUndoableAction (const PaintElementUndoableAction&);
149 PaintElementUndoableAction& operator= (const PaintElementUndoableAction&);
154 #endif // __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__